Add optional HTTP response body consumption checking with -check-consumption flag#75
Merged
timakin merged 3 commits intotimakin:masterfrom Jan 29, 2026
Merged
Conversation
- Add -check-consumption flag to enable body consumption verification - Implement detection for common consumption patterns (io.Copy, io.ReadAll, json.NewDecoder, etc.) - Add comprehensive test suite with 215 test cases covering supported patterns and edge cases - Document limitations and false positive scenarios in README - Maintain full backward compatibility with existing functionality When enabled, the analyzer ensures response bodies are both closed AND consumed, helping prevent resource leaks and incomplete request handling. Supported consumption patterns: - io.Copy(io.Discard, resp.Body) - io.ReadAll(resp.Body) / ioutil.ReadAll(resp.Body) - json.NewDecoder(resp.Body) - bufio.NewScanner(resp.Body) / bufio.NewReader(resp.Body) 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
- Switch from unitchecker to singlechecker for cleaner implementation - Remove unnecessary analyzers() wrapper function - Simplify main function to single line This change improves maintainability and follows best practices for single-analyzer tools. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
9319fc3 to
742a4ad
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Thank you for this excellent analysis tool!
Summary
As mentioned in issue #43, it would be helpful to check not only if
resp.Body.Close()is called, but also whether the response body is actually consumed. This PR implements an optional-check-consumptionflag to provide thisfunctionality.
Motivation
While the current tool ensures bodies are closed, checking consumption is also valuable for:
Implementation
Key Features
-check-consumptionflagSupported Consumption Patterns
io.Copy(io.Discard, resp.Body)io.ReadAll(resp.Body)/ioutil.ReadAll(resp.Body)json.NewDecoder(resp.Body)bufio.NewScanner(resp.Body)/bufio.NewReader(resp.Body)Documentation
Known Limitations
Since detecting all consumption patterns is challenging, some false positives may occur:
//nolint:bodyclosefor false positivesAll limitations are documented in the README with examples.
Compatibility
No impact on existing functionality - the new feature is completely opt-in via the
-check-consumptionflag.Note: This pull request includes commits generated with Claude Code assistance, but I have carefully reviewed and guided the implementation throughout the development process.
This enhancement helps developers write more robust HTTP client code while maintaining the tool's existing simplicity and reliability.